package test2constructor;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.*;
import org.springframework.stereotype.Component;


/**
 * @author: mornd
 * @dateTime: 2023/5/17 - 21:18
 * @Scope 解决构造器产生的循环依赖 （不推荐）
 */
@Slf4j
@ComponentScan
public class Demo4 {
    public static void main(String[] args) {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Demo4.class);
        AAA4 aaa = context.getBean(AAA4.class);
        BBB4 bbb = context.getBean(BBB4.class);
        System.out.println("-------------------------");
        System.out.println(aaa.getClass());
        System.out.println(bbb.getClass());
    }

    @Component
    @Scope(proxyMode = ScopedProxyMode.TARGET_CLASS)
    static class AAA4 {
        public AAA4(BBB4 bbb) {
            log.debug("AAA({})", bbb.getClass().getName());
        }

        public void foo() {
            System.out.println("foo....");
        }
    }

    @Component
    static class BBB4 {

        public BBB4(AAA4 aaa) {
            log.debug("BBB({})", aaa.getClass().getName());
        }
    }
}
